%config InlineBackend.figure_format = "svg"In [1]:
In [2]:
import networkx as nx
import matplotlib.pyplot as pltIn [8]:
fig, ax = plt.subplots(1, 1, figsize=(3, 1.5))
G = nx.DiGraph([
("$A$", "$Y$"),
# ("$X_0$", None),
("$X_A$", "$A$"),
("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"),
("$X_Y$", "$Y$"),
])
G.add_node("$X_0$")
pos = {
"$A$":[0,0], "$Y$":[5,0],
"$X_0$":[1, 2], "$X_A$":[2,2],
"$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}
nx.draw(G, pos=pos, ax=ax, with_labels=True, node_color="white")In [9]:
fig, ax = plt.subplots(1, 1, figsize=(3, 1.5))
G = nx.DiGraph([
("$A$", "$Y$"),
("$X_A$", "$A$"),
("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"),
("$X_Y$", "$Y$"),
])
G.add_node("$X_0$")
pos = {
"$A$":[0,0], "$Y$":[5,0],
"$X_0$":[1, 2], "$X_A$":[2,2],
"$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}
nx.draw(G, pos=pos, ax=ax, with_labels=True, node_color="white")
nx.draw_networkx_edges(
G, pos=pos,
edgelist=[
("$X_0$", "$A$"), ("$X_0$", "$Y$"),
("$X_A$", "$Y$"), ("$X_Y$", "$A$"),
],
style="--",
edge_color="0.25",
ax=ax,
);In [15]:
fig, axes = plt.subplots(1, 2, figsize=(10, 2.5))
G = nx.DiGraph([
("$A$", "$Y$"),
("$X_A$", "$A$"),
("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"),
("$X_Y$", "$Y$"),
])
G.add_node("$X_0$")
pos = {
"$A$":[0,0], "$Y$":[5,0],
"$X_0$":[1, 2], "$X_A$":[2,2],
"$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}
nx.draw(G, pos=pos, ax=axes[1], with_labels=True, node_color="white", font_size=14)
nx.draw(G, pos=pos, ax=axes[0], with_labels=True, node_color="white", font_size=14)
nx.draw_networkx_edges(
G, pos=pos,
edgelist=[
("$X_0$", "$A$"), ("$X_0$", "$Y$"),
("$X_A$", "$Y$"), ("$X_Y$", "$A$"),
],
style="--",
edge_color="#9e3434", # "#d12e2e"
ax=axes[0],
)
axes[0].set_title("Assumed confounding structure", fontsize=14, pad=12)
axes[1].set_title("Actual confounding structure", fontsize=14, pad=12);
fig.subplots_adjust(wspace=0);
# fig.tight_layout();